<template>
	<el-dialog :title="!dataForm.id ? '新建' :  isDetail ? '详情':'编辑'" :close-on-click-modal="false" :visible.sync="visible" class="JNPF-dialog JNPF-dialog_center" lock-scroll width="600px">
		<el-row :gutter="15" class="" >
			<el-form ref="elForm" :model="dataForm" size="medium" label-width="100px" label-position="right" :disabled="!!isDetail" :rules="rules">
				<el-col :span="24">
					<el-form-item label="库区编号" prop="kqbh" required >
						<el-input v-model="dataForm.kqbh" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="库区名称" prop="kqmc" required >
						<el-input v-model="dataForm.kqmc" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="在厂区的位置" prop="zcqdwz" required >
						<el-input v-model="dataForm.zcqdwz" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="所处环境功能区" prop="schjgnq" required >
						<el-input v-model="dataForm.schjgnq" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="库区面积" prop="kqmj" required >
						<el-input v-model="dataForm.kqmj" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="库区个数" prop="kfgs" required >
						<el-input v-model="dataForm.kfgs" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="相邻库房最小间距" prop="xlkfzxjj" required >
						<el-input v-model="dataForm.xlkfzxjj" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="所属重大危险源编码" prop="sswhpzdwxybm" required >
						<el-select v-model="dataForm.sswhpzdwxybm" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in sswhpzdwxybmOptions" :key="index" :label="item.ZDWXYMC" :value="item.ZDWXYBM" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="现场照片" prop="xczp" >
						<JNPF-UploadImg v-model="dataForm.xczp"  accept="" :fileSize="2" sizeUnit="MB" :limit="9" >
						</JNPF-UploadImg>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="经度（度）" prop="jd" required >
						<el-input v-model="dataForm.jd" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="纬度（度）" prop="wd" required >
						<el-input v-model="dataForm.wd" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="备注" prop="bz" >
						<el-input v-model="dataForm.bz" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="所属部门" prop="ssbm" required >
						<el-select filterable v-model="dataForm.ssbm" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in ssbmOptions" :key="index" :label="item.F_FullName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
			</el-form>
		</el-row>
		<span slot="footer" class="dialog-footer">
			<el-button @click="visible = false">取 消</el-button> 
			<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
		</span>
	</el-dialog>

</template>
<script>
import request from '@/utils/request'
import {getDictionaryDataSelector}from '@/api/systemData/dictionary'
import {previewDataInterface}from '@/api/systemData/dataInterface'
export default {
    data() {
      return {
        visible: false,
        isDetail: false,
        dataForm: {
					kqbh:undefined,
					kqmc:undefined,
					zcqdwz:undefined,
					schjgnq:undefined,
					kqmj:undefined,
					kfgs:undefined,
					xlkfzxjj:undefined,
					sswhpzdwxybm:undefined,
					xczp:[],
					jd:undefined,
					wd:undefined,
					bz:undefined,
					ssbm:undefined,

        },
        rules: {
						kqbh:[
						{
							required:true,
							message:'请输入库区编号',
							trigger:'blur'
						},
						],
						kqmc:[
						{
							required:true,
							message:'请输入库区名称',
							trigger:'blur'
						},
						],
						zcqdwz:[
						{
							required:true,
							message:'请输入在厂区的位置',
							trigger:'blur'
						},
						],
						schjgnq:[
						{
							required:true,
							message:'请输入所处环境功能区',
							trigger:'blur'
						},
						],
						kqmj:[
						{
							required:true,
							message:'请输入库区面积',
							trigger:'blur'
						},
						],
						kfgs:[
						{
							required:true,
							message:'请输入库区个数',
							trigger:'blur'
						},
						],
						xlkfzxjj:[
						{
							required:true,
							message:'请输入相邻库房最小间距',
							trigger:'blur'
						},
						],
						sswhpzdwxybm:[
						{
							required:true,
							message:'请输入所属重大危险源编码',
							trigger:'blur'
						},
						],
						jd:[
						{
							required:true,
							message:'请输入经度（度）',
							trigger:'blur'
						},
						],
						wd:[
						{
							required:true,
							message:'请输入纬度（度）',
							trigger:'blur'
						},
						],
						ssbm:[
						{
							required:true,
							message:'请输入所属部门',
							trigger:'blur'
						},
						],

        },
				sswhpzdwxybmOptions:[],
				ssbmOptions:[],

      }
    },
    created() {
		this.getSswhpzdwxybmOptions();
		this.getSsbmOptions();

    },
    methods: {
		getSswhpzdwxybmOptions()
		{
			previewDataInterface('707f1102bce74818a551ebcfa88f2321').then(res => {
				this.sswhpzdwxybmOptions = res.data
			})
		},
		getSsbmOptions()
		{
			previewDataInterface('772d2cbcadd24df79243e3d92ef5f690').then(res => {
				this.ssbmOptions = res.data
			})
		},

           goBack() {
                    this.$emit('refresh')
                },
      init(id, isDetail) {

        this.dataForm.id = id || 0;
        this.visible = true;
        this.isDetail = isDetail || false;
        this.$nextTick(() => {
          this.$refs['elForm'].resetFields();
          if (this.dataForm.id) {
            request({
              url: '/api/System/CKQ/' + this.dataForm.id,
              method: 'get'
            }).then(res =>{
              this.dataForm = res.data;

            })
          }
        })
      },
      // 表单提交
      dataFormSubmit() {
        this.$refs['elForm'].validate((valid) => {
          if (valid) {
            if (!this.dataForm.id) {
              request({
                url: '/api/System/CKQ',
                method: 'post',
                data: this.dataForm,
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            } else {
              request({
                url: '/api/System/CKQ/' + this.dataForm.id,
                method: 'PUT',
                data: this.dataForm
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            }
          }
        })
      },

    }
  }
  </script>